package com.example.demo;

//import com.alibaba.fastjson.JSON;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@EnableScheduling
public class AlarmTask{

    private static final SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
    /**
     * 定义执行线程启动的开关
     * @throws InterruptedException
     */
    @Scheduled(cron = "0/7 * * * * *")
    public void run() throws InterruptedException{
//        Thread.sleep(7000);
        //String time = JSON.toJSONString(format.format(new Date()));
        String time = format.format(new Date());
        System.out.println(Thread.currentThread().getName() + " ======>运行时间" +time);
    }

//    /**
//     * 对上一次执行时间之后再执行的时间
//     * @throws InterruptedException
//     */
//    @Scheduled(fixedRate = 5000)
//    public void run1() throws InterruptedException{
//        Thread.sleep(7000);
//        String time = JSON.toJSONString(format.format(new Date()));
//        System.out.println(Thread.currentThread().getName() + " ==>run2-" +time);
//    }
}
